package atm;

import java.util.Scanner;

/**
 * 单用户版本的ATM
 */
public class ATM01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("欢迎进入XXX银行");
        String sysAccount = "aaaaaa";
        String sysPwd = "111111";
        double sysBlance = 0;

        // 三次比较，如果连续失败则系统退出
        for(int i = 0;i < 3;i++){
            // 登录判断
            System.out.println("请输入账号：");
            String account = sc.next();
            System.out.println("请输入密码：");
            String pwd = sc.next();
            if(sysAccount.equals(account) && sysPwd.equals(pwd)){
                System.out.println("登录成功");
                break;
            }else{
                System.out.println("登录失败，还剩"+(2 - i)+"次");
                if(i == 2){
                    System.out.println("卡已被吞");
                    System.exit(0);
                }
            }

        }


        while(true){
            // 如果登录成功，进入菜单页面
            System.out.println("请选择：1-存款 2-取款 3-查询 4-退出");
            int input = sc.nextInt();
            if(input == 1){
                System.out.println("请输入存的金额：");
                double blance = sc.nextDouble();
                sysBlance += blance;
                System.out.println("存款成功");
            }else if(input == 2){
                System.out.println("请输入取款的金额：");
                double blance = sc.nextDouble();
                if(blance > sysBlance){
                    System.out.println("余额不足");
                }else{
                    sysBlance -= blance;
                    System.out.println("取款成功");
                }
            }else if(input == 3){
                System.out.println("您的余额为："+sysBlance);
            }else if(input == 4){
                // 系统结束
                System.out.println("再见");
                System.exit(0);
            }else{
                System.out.println("输入有误");
            }
        }

    }
}
